// var serviceUrl='http://172.16.31.162:8868';
// var serviceUrl='http://120.79.241.160:8868';

// var serviceUrl1 = 'http://10.10.2.228:8868';
var serviceUrl1 = 'http://bi-test.sqqmall.com';


var serviceUrl = 'http://bi-test.sqqmall.com';

// var   num_s = "1232134456.546";
// console.log(parseFloat(num_s).toLocaleString());

let width = $('.tab-box-swiper>div').parent().prev().find('.active').width();

var className = ["m_index", "m_user", "m_deal", "m_goods"];
$('.tab-box-swiper>div').width(width);
$('.tab-box-swiper>div').css('left', 5);


//导航栏切换
$('.tab-box>div').click(function () {
    let index = $(this).data('index');
    let left = (index * 25) + '%';
    $('.tab-swiper>div').css('left', left);
    $('.tab-box>div').removeClass('active');
    $(this).addClass('active');
    let moveleft = (index * -100) + '%';
    $('.moveBox').css('left', moveleft);
    let num = index + 1;
    getNodesHeight(index);
    // $('.moveBox>div:not(:nth-child('+num+'))').css('height','0');
    // $('.moveBox>div:not(:nth-child('+num+'))').css('opacity','0');
    // $('.moveBox>div:nth-child('+num+')').css('height','300px');
    // $('.moveBox>div:nth-child('+num+')').css('opacity','1');
    document.body.scrollTop = document.documentElement.scrollTop = 0;
})

getNodesHeight(0);

function getNodesHeight(num) {
    var index = num;
    var cruuentNode = document.querySelector("." + className[index]);
    document.querySelector(".moveBox").style.height = cruuentNode.offsetHeight + "px";
    // console.dir();

}

//说明弹出/关闭
var model = function (num, type, text) {
    if (num == 1) {
        document.getElementById('model').style.display = "block";
    } else {
        document.getElementById('model').style.display = "none";
    }
    if (type == 'money') {
        document.getElementById('p1').innerHTML = '会员总余额：注册会员已充值到账户的剩余卡余额';
    } else if (type == 'login') {
        document.getElementById('p1').innerHTML = '用户激活率=注册会员数 / 销售卡数';
    } else if (type == 'msg') {
        document.getElementById('p1').innerHTML = text;
    }
}

// 基础概括数据
var myChart = echarts.init(document.getElementById('main'));
var myChart1 = echarts.init(document.getElementById('main1'));
var option = {
    color: [],
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            label: {
                backgroundColor: '#6a7985'
            }
        }
    },
    legend: {
        data: [],
        left: '2%',
        top: '4%'
    },
    grid: {
        left: '2%',
        right: '3%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'category',
        data: []
    },
    yAxis: {
        type: 'value'
    },
    series: []
};

var basic = function () {
    // console.log(1);
    $.ajax({
        url: serviceUrl1 + '/coupon-bi/bi/basic',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 基础概括数据 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            document.getElementById('basic1').innerHTML = parseFloat(data.data.exchangeAmount).toLocaleString(); //兑换金额
            // document.getElementById('basic2').innerHTML=parseFloat(data.data.exchangePer).toLocaleString(); 
            document.getElementById('basic3').innerHTML = parseFloat(data.data.exchangePerAvg).toLocaleString(); //人均兑换金额
            document.getElementById('basic4').innerHTML = parseFloat(data.data.activeTotal).toLocaleString(); //激活卡数
            document.getElementById('basic5').innerHTML = parseFloat(data.data.activeAmount).toLocaleString(); //激活金额
            document.getElementById('basic6').innerHTML = parseFloat(data.data.totalRemaining).toLocaleString(); //会员总余额
            document.getElementById('basic7').innerHTML = parseFloat(data.data.cardNum).toLocaleString(); //生成卡数
            document.getElementById('basic8').innerHTML = parseFloat(data.data.cardAmount).toLocaleString(); //生成金额
            document.getElementById('basic9').innerHTML = parseFloat(data.data.regUser).toLocaleString(); //注册会员数
            document.getElementById('basic11').innerHTML = parseFloat(data.data.exchangePer).toLocaleString(); //兑换人数
            document.getElementById('basic12').innerHTML = parseFloat(data.data.payAmount).toLocaleString(); //支付金额
            document.getElementById('basic13').innerHTML = parseFloat(data.data.payUser).toLocaleString(); //支付人数

            document.getElementById('basic14').innerHTML = parseFloat(data.data.payUnitPrice).toLocaleString(); //客单价
            document.getElementById('basic15').innerHTML = parseFloat(data.data.estAmount).toLocaleString(); //预估佣金
            document.getElementById('basic16').innerHTML = parseFloat(data.data.payNum).toLocaleString(); //支付笔数
            document.getElementById('basic17').innerHTML = parseFloat(data.data.settleUserAmount).toLocaleString(); //人均结算佣金
            document.getElementById('basic18').innerHTML = parseFloat(data.data.settleAmount).toLocaleString(); //结算佣金
            document.getElementById('basic19').innerHTML = parseFloat(data.data.settleOrder).toLocaleString(); //已结算订单
            document.getElementById('basic10').innerHTML = parseFloat(data.data.regUserRate).toLocaleString(); //激活人数
        },


        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
basic();

/* 折现图模块 */
var lastDay = {}; //昨日
var last7day = {}; //近七天
var last30day = {}; //近30天
var lastMonth = {}; //月
var activatingType = 0; //时间type
var tabType = 0; //切换type
//激活卡数、激活金额、兑换金额
var activatingCard = function (text) {
    $.ajax({
        url: serviceUrl + text,
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 激活卡数、激活金额、兑换金额 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            lastDay = data.data.lastDay;
            last7day = data.data.last7day;
            last30day = data.data.last30day;
            lastMonth = data.data.lastMonth;

            switch (activatingType) {
                case 0:
                    lineChart(0);
                    break;
                case 1:
                    lineChart(1, '近7日', last7day);
                    break;
                case 2:
                    lineChart(2, '近30日', last30day);
                    break;
                case 3:
                    lineChart(3, '月', lastMonth);
                    break;
                default:
                    console.log('其他')
            }

            // lineChart(activatingType,'近7日',last7day);
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
//激活信息切换
$('.activating-tab-box>div').click(function () {
    var index = $(this).index();
    tabType = index;
    var left = index * 56 + (2 * index + 1) * 12;
    $('.activating-tab-swiper>div').css('margin-left', left);
    $('.activating-tab-box>div').removeClass('active');
    $(this).addClass('active');
    switch (index) {
        case 0:
            activatingCard('/coupon-bi/bi/activeCard');
            break;
        case 1:
            activatingCard('/coupon-bi/bi/activeAmount');
            break;
        case 2:
            activatingCard('/coupon-bi/bi/exchangeAmount');
            break;
        default:
            console.log('其他')
    }
})
var option222 = {
    color: ['#00D0D0'],
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            label: {
                backgroundColor: '#6a7985'
            }
        }
    },
    legend: {
        data: [],
        left: '2%',
        top: '4%'
    },
    grid: {
        left: '2%',
        right: '3%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'category',
        data: []
    },
    yAxis: {
        type: 'value'
    },
    series: []
};

var lineChart = function (index, text, dayArr) {
    if (index == 0) {
        $('#main').css('display', 'block');
        $('#main1').css('display', 'none');
        option.legend.data = ['昨日', '上一日']; //分类
        option.color = ['#00D0D0', '#FF9900']; //颜色
        var arrs = [{
                name: '昨日',
                type: 'line',
                data: []
            },
            {
                name: '上一日',
                type: 'line',
                data: []
            }
        ];
        var timeArrs = [];
        for (var i = 0; i < lastDay.currentRound.length; i++) {
            arrs[0].data.push(lastDay.currentRound[i].totalCount);
            timeArrs.push(lastDay.currentRound[i].theTime);
        }
        for (var i = 0; i < lastDay.lastRound.length; i++) {
            arrs[1].data.push(lastDay.lastRound[i].totalCount);
        }
        // console.log(timeArr);
        var tabTime = `昨日 <text>（${lastDay.dateBeginEnd}）</text>`;
        document.getElementById('timeTabTime').innerHTML = tabTime;
        var extentHtml = `
            <text>${parseFloat(lastDay.activieTotal).toLocaleString()} </text> ${tabType==0?'张':'元'} 
            <text>上一日 ${parseFloat(lastDay.lastActivieTotal).toLocaleString()} </text>
            <text class="${lastDay.activieTotal-lastDay.lastActivieTotal>=0?'greed':'red'}">${lastDay.activieTotal-lastDay.lastActivieTotal>=0?'↑':'↓'} ${lastDay.rat}</text>
        `
        document.getElementById('timeTabExtent').innerHTML = extentHtml;
        option.series = [];
        option.xAxis.data = [];
        var newobj = {
            name: '平均值',
            type: 'line', // 平均值
            data: (function () {
                let sum = []
                for (let i in arrs) {
                    for (let j in arrs[i].data) {
                        if (!sum[j]) {
                            sum[j] = 0
                        }
                        sum[j] += arrs[i].data[j] / 2
                    }
                }
                return sum
            })(),
            itemStyle: {
                opacity: 0
            },
            lineStyle: {
                opacity: 0
            },
            markLine: {
                data: [{
                    type: 'average',
                    name: '平均数',
                    label: {
                        normal: {
                            position: 'middle',
                            formatter: '{b}: {c}'
                        }
                    }
                }]
            }
        }
        arrs.push(newobj);
        option.series = arrs;
        option.xAxis.data = timeArrs;
        myChart.setOption(option);
    } else {
        $('#main').css('display', 'none');
        $('#main1').css('display', 'block');
        option222.legend.data = [text]; //分类
        var arr = [{
            name: text,
            type: 'line',
            data: []
        }];
        var timeArr = [];
        var Arr = dayArr;

        for (var i = 0; i < Arr.currentRound.length; i++) {
            arr[0].data.push(Arr.currentRound[i].totalCount);
            timeArr.push(Arr.currentRound[i].theTime);
        }
        // console.log(Arr);
        var tabTime = `${text} <text>（${Arr.dateBeginEnd}）</text>`;
        document.getElementById('timeTabTime').innerHTML = tabTime;
        var extentHtml = `
            <text>${parseFloat(Arr.activieTotal).toLocaleString()} </text> ${tabType==0?'张':'元'}
            <text>${text=='近7日'?"上一个7日":(text=='近30日'?"上一个30日":"上月")} ${parseFloat(Arr.lastActivieTotal).toLocaleString()} </text>
            <text class="${Arr.activieTotal-Arr.lastActivieTotal>=0?'greed':'red'}">${Arr.activieTotal-Arr.lastActivieTotal>=0?'↑':'↓'} ${Arr.rat}</text>
        `
        document.getElementById('timeTabExtent').innerHTML = extentHtml;
        var newobj = {
            name: '平均值',
            type: 'line', // 平均值
            data: (function () {
                let sum = []
                for (let i in arr) {
                    for (let j in arr[i].data) {
                        if (!sum[j]) {
                            sum[j] = 0
                        }
                        sum[j] += arr[i].data[j]
                    }
                }
                return sum
            })(),
            itemStyle: {
                opacity: 0
            },
            lineStyle: {
                opacity: 0
            },
            markLine: {
                data: [{
                    type: 'average',
                    name: '平均数',
                    label: {
                        normal: {
                            position: 'middle',
                            formatter: '{b}: {c}'
                        }
                    }
                }]
            }
        }
        arr.push(newobj);
        option222.series = arr;
        option222.xAxis.data = timeArr;
        myChart1.setOption(option222);
    }
};
activatingCard('/coupon-bi/bi/activeCard');

//激活信息查看时间切换
$('.time-tab-change>div').click(function () {
    var index = $(this).index();
    activatingType = index;
    switch (index) {
        case 0:
            lineChart(0);
            break;
        case 1:
            lineChart(1, '近7日', last7day);
            break;
        case 2:
            lineChart(2, '近30日', last30day);
            break;
        case 3:
            lineChart(3, '月', lastMonth);
            break;
        default:
            console.log('其他')
    }
    // console.log(option)
    $('.time-tab-change>div').removeClass('active');
    $(this).addClass('active');
    // myChart.setOption(option);
})





//定制卡排行榜
var createAmountTop10 = []; //生成金额
var activeAmountTop10 = []; //激活金额
var exchangeAmountTop10 = []; //兑换金额
var createCardTop10 = []; //生成卡数
var activeCardTop10 = []; //激活卡数
var rankTab = 0; //默认为金额
var rankTablength = 3; //数量记录
var moneyTablength = 0; //金额记录
var cardRankingHtml = ''; //HTML
// 普通卡图形
var myChartpie1 = echarts.init(document.getElementById('pie1'));
var peioption1 = {
    tooltip: {
        trigger: 'item',
        position: [0, 0],
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    color: ['#FF9945', '#4CDFC2', '#5EB0EF', '#F9CF2B'],
    series: [{
        name: '生成卡的数量',
        type: 'pie',
        radius: ['50%', '70%'],
        avoidLabelOverlap: false,
        label: {
            normal: {
                show: false,
                position: 'center'
            },
            emphasis: {
                show: true,
                textStyle: {
                    fontSize: '16',
                    fontWeight: '500',
                    shadowOffsetY: '0'
                }
            }
        },
        labelLine: {
            normal: {
                show: true
            }
        },
        data: []
    }]
};
// 定制卡
var myChartpie2 = echarts.init(document.getElementById('pie2'));
var peioption2 = {
    tooltip: {
        trigger: 'item',
        position: [0, 0],
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    color: ['#F3f3f3', '#4CDFC2', '#5EB0EF', '#F9CF2B'],
    series: [{
        name: '生成卡的数量',
        type: 'pie',
        radius: ['50%', '70%'],
        avoidLabelOverlap: false,
        label: {
            normal: {
                show: false,
                position: 'center'
            },
            emphasis: {
                show: true,
                textStyle: {
                    fontSize: '16',
                    fontWeight: '500',
                    shadowOffsetY: '0'
                }
            }
        },
        labelLine: {
            normal: {
                show: true
            }
        },
        data: []
    }]
};
var cardRanking = function () {
    $.ajax({
        url: serviceUrl + '/coupon-bi/bi/customCardAnalyze',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 定制卡排行榜 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            createAmountTop10 = data.data.createAmountTop10;
            activeAmountTop10 = data.data.activeAmountTop10;
            exchangeAmountTop10 = data.data.exchangeAmountTop10;
            createCardTop10 = data.data.createCardTop10;
            activeCardTop10 = data.data.activeCardTop10;
            rankingHtml(createAmountTop10);
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
var rankingHtml = function (arr) {
    cardRankingHtml = '';
    if (rankTab == 1) {
        cardRankingHtml = `
            <div>
                <div>排名</div>
                <div class='times'>公司名称</div>   
                <div class="ranking-tab-dz ${rankTablength==3?'active':''}" data-index='3'>生成卡数 <i></i></div>
                <div class="ranking-tab-dz ${rankTablength==4?'active':''}" data-index='4'>激活卡数 <i></i></div>
               
            </div>
        `;
        $.each(arr, function (key, value) {
            // console.log(value);
            cardRankingHtml += `
                <div>
                    <div>${value.rowNum}</div>
                    <div class='times'>${value.name}</div>
                    <div>${parseFloat(value.totalCount).toLocaleString()}</div>
                    <div>${parseFloat(value.totalRechargeCardno).toLocaleString()}</div>
                </div>
            `;
        })
        document.getElementById('canvasHeadtext').innerHTML = '（单位：张）';
    } else {
        var cardRankingHtml = `
            <div>
                <div>排名</div>
                <div>公司名称</div>   
                <div class="ranking-tab-dz ${moneyTablength==0?'active':''}" data-index='0'>生成金额 <i></i></div>
                <div class="ranking-tab-dz ${moneyTablength==1?'active':''}" data-index='1'>激活金额 <i></i></div>
                <div class="ranking-tab-dz ${moneyTablength==2?'active':''}" data-index='2'>兑换金额 <i></i> </div>
            </div>
        `;
        $.each(arr, function (key, value) {
            // console.log(value);
            cardRankingHtml += `
                <div>
                    <div>${value.rowNum}</div>
                    <div>${value.name}</div>
                    <div>${parseFloat(value.companyValue).toLocaleString()}</div>
                    <div>${parseFloat(value.companyActivatedValue).toLocaleString()}</div>
                    <div>${parseFloat(value.comanyRechargeValue).toLocaleString()}</div>
                </div>
            `;
        })
        document.getElementById('canvasHeadtext').innerHTML = '（单位：元）';
    }
    document.getElementById('ranking').innerHTML = cardRankingHtml;
}
cardRanking();
//定制卡排行榜
$('.dzcard-tab>div').click(function () {
    // console.log(rankTablength);
    if ($(this).index() == 0) {
        rankTab = 0;
        if (moneyTablength == 0) {
            rankingHtml(createAmountTop10);
        } else if (moneyTablength == 1) {
            rankingHtml(activeAmountTop10);
        } else if (moneyTablength == 2) {
            rankingHtml(exchangeAmountTop10);
        }
    } else {
        rankTab = 1;
        if (rankTablength == 3) {
            rankingHtml(createCardTop10);
        } else if (rankTablength == 4) {
            rankingHtml(activeCardTop10);
        }
    }
    $('.dzcard-tab>div').removeClass('active');
    $(this).addClass('active');
})
//定制卡金额切换
$('#ranking').on('click', '.ranking-tab-dz', function () {
    $('.ranking-tab-dz').removeClass('active');
    $(this).addClass('active');
    if ($(this).data('index') == 0) {
        moneyTablength = 0;
        rankingHtml(createAmountTop10);
    } else if ($(this).data('index') == 1) {
        moneyTablength = 1;
        rankingHtml(activeAmountTop10);
    } else if ($(this).data('index') == 2) {
        moneyTablength = 2;
        rankingHtml(exchangeAmountTop10);
    } else if ($(this).data('index') <= 3) {
        rankTablength = 3
        rankingHtml(createCardTop10);
    } else if ($(this).data('index') == 4) {
        rankTablength = 4
        rankingHtml(activeCardTop10);
    }
})

//生成卡各面值金额占比
function uniq(array) {
    var temp = []; //一个新的临时数组
    for (var i = 0; i < array.length; i++) {
        if (temp.indexOf(array[i]) == -1) {
            temp.push(array[i]);
        }
    }
    return temp;
}
var cardMoneyColorArr = ['#55ABEF', '#4AE0C2', '#FF9946', '#F9CF2B', '#788BF1', '#2FC993', '#FEC580', '#5F74F3', '#F09489', '#42496D'];
var cardMoney = function () {
    $.ajax({
        url: serviceUrl + '/coupon-bi/bi/cardFaceAnalyze',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 生成卡各面值金额占比 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            let customCardArr = []; //定制卡数据
            let normalCardArr = []; //普通卡数据
            var allArr = []; //所有卡的面值
            var allColorArr = []; //所有卡的面值对应颜色
            for (var i = 0; i < data.data.customCard.length; i++) {
                var obj = {
                    value: '',
                    name: ''
                };
                obj.value = data.data.customCard[i].totalCount;
                obj.name = data.data.customCard[i].faceValue + '元';
                if (data.data.customCard.length <= 0) {
                    obj.value = 0;
                    obj.name = '暂无';
                }
                customCardArr.push(obj);
                // console.log(customCardArr);
                allArr.push(data.data.customCard[i].faceValue + '元');
            }
            if (data.data.customCard.length <= 0) {
                var obj = {
                    value: '',
                    name: ''
                };
                obj.value = 0;
                obj.name = '暂无';
                customCardArr.push(obj);
            }
            // console.log(customCardArr);
            for (var j = 0; j < data.data.normalCard.length; j++) {
                var obj = {
                    value: '',
                    name: ''
                };
                obj.value = data.data.normalCard[j].totalCount;
                obj.name = data.data.normalCard[j].faceValue + '元';
                normalCardArr.push(obj);
                allArr.push(data.data.normalCard[j].faceValue + '元');
            }
            // console.log(normalCardArr);
            // console.log(allArr);
            allArr = uniq(allArr)

            // console.log(allArr);

            for (var a = 0; a < allArr.length; a++) {
                allColorArr.push(cardMoneyColorArr[a]);
            }
            // console.log(allColorArr);

            //定制卡颜色数组生成
            var customCardColorArr = [];
            for (var c = 0; c < customCardArr.length; c++) {
                for (var d = 0; d < allArr.length; d++) {
                    if (customCardArr[c].name == allArr[d]) {
                        customCardColorArr.push(allColorArr[d]);
                    }
                }
            }
            // console.log(customCardColorArr);
            //普通卡颜色数组生成
            var normalCardColorArr = [];
            for (var c = 0; c < normalCardArr.length; c++) {
                for (var d = 0; d < allArr.length; d++) {
                    if (normalCardArr[c].name == allArr[d]) {
                        // console.log(allColorArr[d]);
                        normalCardColorArr.push(allColorArr[d]);
                    }
                }
            }
            if (data.data.customCard.length <= 0) {
                customCardColorArr.push('#f3f3f3');
            }
            // console.log(normalCardColorArr);

            peioption1.series[0].data = normalCardArr;
            peioption2.series[0].data = customCardArr;
            peioption1.color = normalCardColorArr;
            peioption2.color = customCardColorArr;
            document.getElementById('customCardSum').innerHTML = parseFloat(data.data.customerTotal).toLocaleString();
            document.getElementById('normalCardSum').innerHTML = parseFloat(data.data.normalTotal).toLocaleString();
            myChartpie1.setOption(peioption1);
            // console.log(peioption2);
            myChartpie2.setOption(peioption2);

            //模块底部颜色生成
            var coloeHtml = '';
            // console.log(allArr);
            $.each(allArr, function (key, value) {
                // console.log(value);
                coloeHtml += `<div><div style="background: ${allColorArr[key]}"></div>${value}</div>`;
            })
            document.getElementById('cardMsgColor').innerHTML = coloeHtml;
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
cardMoney();

//各平台优惠券兑换情况分析
var amountArr = []; //兑换金额
var personArr = []; //兑换次数
var moneySum = ''; //总金额
var timesSum = ''; //总次数
var couponDistributed = function () {
    $.ajax({
        url: serviceUrl + '/coupon-bi/bi/platformAnalyze',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 各平台优惠券兑换情况分析 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            for (var i = 0; i < data.data.amount.length; i++) {
                var obj = {
                    value: '',
                    name: ''
                };
                obj.value = data.data.amount[i].totalAmount;
                obj.name = data.data.amount[i].deduction;
                amountArr.push(obj);
            }
            for (var i = 0; i < data.data.person.length; i++) {
                var obj = {
                    value: '',
                    name: ''
                };
                obj.value = data.data.person[i].totalCustomer;
                obj.name = data.data.person[i].deduction;
                personArr.push(obj);
            }
            // console.log(amountArr);
            // console.log(personArr);
            moneySum = data.data.totalAmount;
            timesSum = data.data.totalPerson;
            peioption3.series[0].data = amountArr;
            document.getElementById('textSum').innerHTML = parseFloat(moneySum).toLocaleString();
            myChartpie3.setOption(peioption3);
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
couponDistributed();
//各平台优惠券兑换情况分析
var myChartpie3 = echarts.init(document.getElementById('pie3'));
var peioption3 = {
    tooltip: {
        trigger: 'item',
        position: [0, 0],
        formatter: "{a} <br/>{b}: {c} ({d}%)"
    },
    color: ['#55ABEF', '#4AE0C2', '#FF9946', '#F9CF2B', '#788BF1', '#2FC993', '#FEC580', '#5F74F3', '#F09489', '#42496D'],
    series: [{
        name: '优惠券兑换情况',
        type: 'pie',
        radius: ['35%', '50%'],
        avoidLabelOverlap: false,
        label: {
            normal: {
                formatter: '{b|{b}  {d}%}',
                rich: {
                    b: {
                        fontSize: 12,
                        lineHeight: 310
                    },
                    per: {
                        color: '#eee',
                        backgroundColor: '#334455',
                        padding: [2, 4],
                        borderRadius: 2
                    }
                }
            },
            emphasis: {
                show: true,
                textStyle: {
                    fontSize: '16',
                    fontWeight: '500',
                    shadowOffsetY: '0'
                }
            }
        },
        labelLine: {
            normal: {
                show: true
            }
        },
        data: [],
        itemStyle: {
            emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
        }
    }]
};
$('.dhcoupon-tab>div').click(function () {
    var index = $(this).index();
    var html = "（单位：元）";
    $('.dhcoupon-tab>div').removeClass('active');
    $(this).addClass('active');
    if (index == 0) {
        peioption3.series[0].data = amountArr;
        document.getElementById('textSum').innerHTML = parseFloat(moneySum).toLocaleString();
    } else {
        html = "（单位：次）"
        peioption3.series[0].data = personArr;
        document.getElementById('textSum').innerHTML = parseFloat(timesSum).toLocaleString();
    }
    document.getElementById('canvasHeadText').innerHTML = html;
    myChartpie3.setOption(peioption3);
})


//优惠券兑换次数商品排行榜
// var couponRanking = function () {
//     $.ajax({
//         url: serviceUrl + '/coupon-bi/bi/skuAnalyze',
//         type: 'get',
//         dataType: 'json',
//         headers: {
//             "Content-Type": "text/plain;charset=UTF-8"
//         },
//         success: function (data, status) {
//             console.log('/**** 优惠券兑换次数商品排行榜 ****/');
//             console.log(data);
//             if (data.code != 0) {
//                 model(1, 'msg', data.msg);
//                 return
//             }
//             var arr = data.data.top10;
//             var ranking = [];
//             var RankingHtml = `
//                 <div>
//                     <div>排行</div>
//                     <div>商品名称</div>
//                     <div>兑换次数</div>
//                 </div>
//             `;
//             $.each(arr, function (key, value) {
//                 // console.log(value);
//                 RankingHtml += `
//                     <div>
//                         <div>${value.rowNum}</div>
//                         <div>
//                             ${value.deduction}--${value.skuName}
//                         </div>

//                         <div>${parseFloat(value.skuCount).toLocaleString()}</div>
//                     </div>
//                 `;
//             })
//             document.getElementById('productRanking').innerHTML = RankingHtml;
//         },
//         fail: function (err, status) {
//             console.log(err);
//             model(1, 'msg', err.msg);
//         }
//     })
// }
// couponRanking();


// 用户账户余额人数统计

var userAccount = function () {
    // console.log(1);
    $.ajax({
        url: serviceUrl1 + '/coupon-bi/bi/userAccount',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 用户账户余额人数统计****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            document.getElementById('userAccount0').innerHTML = parseFloat(data.data.balance0).toLocaleString();
            document.getElementById('userAccount50').innerHTML = parseFloat(data.data.balance50).toLocaleString();
            document.getElementById('userAccount100').innerHTML = parseFloat(data.data.balance100).toLocaleString();
            document.getElementById('userAccount200').innerHTML = parseFloat(data.data.balance200).toLocaleString();
            document.getElementById('userAccount300').innerHTML = parseFloat(data.data.balance300).toLocaleString();

        },


        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
userAccount();



// 用户账户余额为0元趋势分析start
var myChartA = echarts.init(document.getElementById('userOvertozero'));

var optionA = {
    backgroundColor: '#FBFBFB',
    tooltip: {
        trigger: 'axis'
    },
    calculable: true,
    xAxis: [{
        type: 'category',
        boundaryGap: false,
        // data: ['04-01', '04-07', '04-13', '04-24', '04-29']
        data: []
    }],
    yAxis: [{
        type: 'value',
    }],
    grid: {
        top: '16%', // 等价于 y: '16%'
        left: '3%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    series: [{
        type: 'line',
        symbol: 'circle',
        color: ['#66AEDE'],
        // data: [900, 500, 780, 1200, 500],
        data: [],
        lineStyle: {
            width: 1, // 设置线宽
        }
    }]
};

var balanceAnalyze = function () {
    $.ajax({
        url: serviceUrl1 + '/coupon-bi/bi/balanceAnalyze',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 用户账户余额为0元趋势分析 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }

            var tiembalance = []; //时间
            var arrbalance = []; //数据
            for (var i = 0; i < data.data.balance.length; i++) {
                arrbalance.push(data.data.balance[i].total);
                tiembalance.push(data.data.balance[i].day);
            }

            optionA.xAxis[0].data = tiembalance;
            optionA.series[0].data = arrbalance;
            myChartA.setOption(optionA);
            // debugger
            var timetabs = `<div>(${data.data.beginDate}至${data.data.endDate}近30天 单位：个)</div>`;
            document.getElementById('canvas-head-text1').innerHTML = timetabs;
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }


    })
}

balanceAnalyze();

// 用户账户余额为0元趋势分析end



/* 折现图模块 */
var lastDay = {}; //昨日
var last7day = {}; //近七天
var last30day = {}; //近30天
var lastMonth = {}; //月
var timeType = 0; //时间type
var tabType = 0; //切换type
var myChartB = echarts.init(document.getElementById('userLoginPay1'));
var myChartz = echarts.init(document.getElementById('userLoginPay2'));
var option1 = {
    color: [],
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            label: {
                backgroundColor: '#6a7985'
            }
        }
    },
    legend: {
        data: [],
        left: '2%',
        top: '4%'
    },
    grid: {
        left: '2%',
        right: '3%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'category',
        data: []
    },
    yAxis: {
        type: 'value'
    },
    series: [{
            name: '昨日',
            type: 'line',
            symbol: 'circle',
            lineStyle: {
                width: 1, // 设置线宽
            },
            data: []
        },
        {
            name: '上一日',
            type: 'line',
            symbol: 'circle',
            lineStyle: {
                width: 1, // 设置线宽
            },
            data: []
        }
    ]
};

// 注册用户、激活兑换、支付人数 切换 
$('.tab-box-model1>div').click(function () {
    var index = $(this).index();
    tabType = index;
    var left = index * 56 + (2 * index + 1) + 12;
    $('.tab-box-swiper1>div').css('width', $(this).css('width'))
    $('.tab-box-swiper1>div').css('margin-left', left);
    $(this).addClass('activem');
    $(this).siblings().removeClass('activem');
    switch (tabType) {
        case 0:
            regUser(0, '/coupon-bi/bi/regUser');
            break;
        case 1:
            regUser(1, '/coupon-bi/bi/actExgPayUser');
            break;
        default:
            console.log('其他')
    }
})


//注册用户 激活兑换/支付人数
var regUser = function (tabType, text) {
    console.log(tabType);
    $.ajax({
        url: serviceUrl1 + text,
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 注册用户 激活兑换/支付人数 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }

            lastDays = data.data.lastDay;
            last7days = data.data.last7day;
            last30days = data.data.last30day;
            lastMonths = data.data.lastMonth;

            if (tabType == 0) {
                document.getElementById('regtop').innerHTML = '';
                document.getElementById('regs').innerHTML = '';
            } else {
                let regs = ''
                regs = `
                    <div>
                        <div>${lastDays.activieTotal}</div>
                    </div>

                    <div>
                        <div>${lastDays.lastActivieTotal}</div>
                    </div>

                    <div>
                        <div>${lastDays.payUser}</div>
                    </div>
                 `
                document.getElementById('regs').innerHTML = regs;
            }


            if (tabType == 0) {
                switch (timeType) {
                    case 0:
                        regUserlineChart1(0, '昨日', lastDays, tabType);
                        break;
                    case 1:
                        regUserlineChart1(1, '近7日', last7days, tabType);
                        break;
                    case 2:
                        regUserlineChart1(2, '近30日', last30days, tabType);
                        break;
                    case 3:
                        regUserlineChart1(3, '月', lastMonths, tabType);
                        break;
                    default:
                        console.log('其他')
                }
                // console.log(111111);
            } else {
                switch (timeType) {
                    case 0:
                        regUserlineChart2(0, '昨日', lastDays, tabType);
                        break;
                    case 1:
                        regUserlineChart2(1, '近7日', last7days, tabType);
                        break;
                    case 2:
                        regUserlineChart2(2, '近30日', last30days, tabType);
                        break;
                    case 3:
                        regUserlineChart2(3, '月', lastMonths, tabType);
                        break;
                    default:
                        console.log('其他')
                }
            }
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
regUser(0, '/coupon-bi/bi/regUser');
var option2 = {
    backgroundColor: '#FBFBFB',
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            label: {
                backgroundColor: '#6a7985'
            }
        }
    },
    legend: {
        data: [],
        align: 'left',
        left: 10,
        icon: "rect", //  字段控制形状  类型包括 circle，rect,line，roundRect，triangle，diamond，pin，arrow，none
        itemWidth: 10, //图例标记的图形宽度
        itemHeight: 10,
        itemGap: 10 // 设置间距
    },
    calculable: true,
    xAxis: [{
        type: 'category',
        boundaryGap: false,
        data: []
    }],
    yAxis: [{
        type: 'value'
    }],
    grid: {
        top: '16%', // 等价于 y: '16%'
        left: '3%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    series: [{
            name: '激活人数',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(0, 208, 208, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            name: '兑换人数',
            type: 'line',
            symbol: 'circle',
            color: ['#FF9946'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }


        },
        {
            name: '支付人数',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(0, 128, 0, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        }
    ]
};

var regUserlineChart2 = function (index, test, list, index2) {
    
    document.getElementById('timeTab').innerHTML = '';
    document.getElementById('timeTabExtent1').innerHTML = '';
    // option2.legend.data = ['激活人数', '兑换人数', '支付人数']; //分类
    option2.color = ['rgba(0, 208, 208, 1)', '#FF9900', 'rgba(0, 128, 0, 1)']; //颜色

    let activieRound = []; //激活数据
    let activietime = []; //时间x轴
    // console.log(list.activieRound);

    for (var i = 0; i < list.activieRound.length; i++) {
        activieRound.push(list.activieRound[i].totalCount);
        activietime.push(list.activieRound[i].theTime);
    }
    option2.xAxis[0].data = activietime;
    option2.series[0].data = activieRound;

    let exchangeRound = []; //兑换人数数据
    for (var i = 0; i < list.exchangeRound.length; i++) {
        exchangeRound.push(list.exchangeRound[i].totalCount);
    }
    option2.series[1].data = exchangeRound;

    let payRound = []; //支付人数数据
    for (var i = 0; i < list.payRound.length; i++) {
        payRound.push(list.payRound[i].totalCount);
    }
    option2.series[2].data = payRound;
    console.log(option2);
    myChartz.setOption(option2);

    if (tabType == 0) {
        document.getElementById('regtop').innerHTML = '';
        document.getElementById('regs').innerHTML = '';
    } else {
        let regs = ''
        regs = `
            <div>
                <div><i class="i1"></i>激活人数</div>
                <div class="num">${parseFloat(list.activieTotal).toLocaleString()}</div>
            </div>

            <div>
                <div><i class="i2"></i>兑换人数</div>
                <div class="num">${parseFloat(list.lastActivieTotal).toLocaleString()}</div>
                </div>
            </div>

            <div>
                <div><i class="i3"></i>支付人数</div>
                <div class="num">${parseFloat(list.payUser).toLocaleString()}</div>
                </div>
            </div>
         `
        document.getElementById('regs').innerHTML = regs;
        $('#userLoginPay1').css('display', 'none');
        $('#userLoginPay2').css('display', 'block');
    }
}




var regUserlineChart1 = function (index, text, dayArr) {
    $('#userLoginPay1').css('display', 'block');
        $('#userLoginPay2').css('display', 'none');
    if (index == 0) { 
        option1.legend.data = ['昨日', '上一日', '平均']; //分类
        option1.color = ['#00D0D0', '#FF9900', 'rgba(0, 128, 0, 1)']; //颜色

        var ruarrs = [{
                name: '昨日',
                type: 'line',
                symbol: 'circle',
                lineStyle: {
                    width: 1, // 设置线宽
                },
                data: []
            },
            {
                name: '上一日',
                type: 'line',
                symbol: 'circle',
                lineStyle: {
                    width: 1, // 设置线宽
                },
                data: []
            }
        ];
        var timeArrs = [];
        // debugger
        console.log(lastDays);
        for (var i = 0; i < lastDays.currentRound.length; i++) {
            ruarrs[0].data.push(lastDays.currentRound[i].totalCount);
            timeArrs.push(lastDays.currentRound[i].theTime);
        };
        for (var i = 0; i < lastDays.lastRound.length; i++) {
            ruarrs[1].data.push(lastDays.lastRound[i].totalCount);
        }
        // console.log(timeArr);
        var timeTab = `昨日 <text>（${lastDays.dateBeginEnd}）</text>`;
        document.getElementById('timeTab').innerHTML = timeTab;
        var extentHtml = `
        <text>上一日 ${parseFloat(lastDays.lastActivieTotal).toLocaleString()} </text>
        <text class="${lastDays.activieTotal-lastDays.lastActivieTotal>=0?'greed':'red'}">${lastDays.activieTotal-lastDays.lastActivieTotal>=0?'↑':'↓'} ${lastDays.rat}</text>
    `
        document.getElementById('timeTabExtent1').innerHTML = extentHtml;
        option1.series = [];
        option1.xAxis.data = [];


        var newobj = {
            name: '平均值',
            type: 'line', // 平均值
            data: (function () {
                let sum = []
                for (let i in ruarrs) {
                    for (let j in ruarrs[i].data) {
                        if (!sum[j]) {
                            sum[j] = 0
                        }
                        sum[j] += ruarrs[i].data[j] / 2
                    }
                }
                return sum
            })(),
            itemStyle: {
                opacity: 0
            },
            lineStyle: {
                opacity: 0
            },
            markLine: {
                data: [{
                    type: 'average',
                    name: '平均数',
                    label: {
                        normal: {
                            position: 'middle',
                            formatter: '{b}: {c}'
                        }
                    }
                }]
            }
        }
        ruarrs.push(newobj);
        option1.series = ruarrs;
        option1.xAxis.data = timeArrs;
        myChartB.setOption(option1);
        // $('#userLoginPay1').css('display', 'block');
        // $('#userLoginPay2').css('display', 'none');
    } else {
        
        option1.legend.data = [text]; //分类
        var arrd = [{
            name: text,
            type: 'line',
            data: []
        }];
        var timeArrs = [];
        for (var i = 0; i < dayArr.currentRound.length; i++) {
            arrd[0].data.push(dayArr.currentRound[i].totalCount);
            timeArrs.push(dayArr.currentRound[i].theTime);
        }
        // console.log(dayArr.currentRound);
        var timeTab = `昨日 <text>（${dayArr.dateBeginEnd}）</text>`;
        document.getElementById('timeTab').innerHTML = timeTab;

        var extentHtml = `
            <text>${parseFloat(dayArr.activieTotal).toLocaleString()}<text class="ren">人</text> </text>
            <text>${text=='近7日'?"上一个7日":(text=='近30日'?"上一个30日":"上月")} ${parseFloat(dayArr.lastActivieTotal).toLocaleString()} </text>
            <text class="${dayArr.activieTotal-dayArr.lastActivieTotal>=0?'greed':'red'}">${dayArr.activieTotal-dayArr.lastActivieTotal>=0?'↑':'↓'} ${dayArr.rat}</text>
        `
        document.getElementById('timeTabExtent1').innerHTML = extentHtml;
        option1.series = [];
        option1.xAxis.data = [];
        var newobj1 = {
            name: '平均值',
            type: 'line', // 平均值
            data: (function () {
                let sum = []
                for (let i in arrd) {
                    for (let j in arrd[i].data) {
                        if (!sum[j]) {
                            sum[j] = 0
                        }
                        sum[j] += arrd[i].data[j]
                    }
                }
                return sum
            })(),
            itemStyle: {
                opacity: 0
            },
            lineStyle: {
                opacity: 0
            },
            markLine: {
                data: [{
                    type: 'average',
                    name: '平均数',
                    label: {
                        normal: {
                            position: 'middle',
                            formatter: '{b}: {c}'
                        }
                    }
                }]
            }
        }
        arrd.push(newobj1);
        option1.series = arrd;
        option1.xAxis.data = timeArrs;
        myChartz.setOption(option1);
    }
}
regUser(0, '/coupon-bi/bi/regUser');

//注册用户、激活兑换支付人数时间切换
$('.time-tab-change1>div').click(function () {
    var index = $(this).index();
    timeType = index;

    if (tabType == 0) {
        switch (index) {
            case 0:
                regUserlineChart1(0, '昨日', lastDays, 0);
                break;
            case 1:
                regUserlineChart1(1, '近7日', last7days, 0);
                break;
            case 2:
                regUserlineChart1(2, '近30日', last30days, 0);
                break;
            case 3:
                regUserlineChart1(3, '月', lastMonths, 0);
                break;
            default:
                console.log('其他')
        }
    } else {
        switch (index) {
            case 0:
                regUserlineChart2(0, '昨日', lastDays, 1);
                break;
            case 1:
                regUserlineChart2(1, '近7日', last7days, 1);
                break;
            case 2:
                regUserlineChart2(2, '近30日', last30days, 1);
                break;
            case 3:
                regUserlineChart2(3, '月', lastMonths, 1);
                break;
            default:
                console.log('其他')
        }
    }


    $('.time-tab-change1>div').removeClass('active');
    $(this).addClass('active');
})
// 注册用户、激活兑换支付人数end



// 各平台兑换、支付趋势分析start
/* 折现图模块 */
var yesterday = {}; //昨日
var last7th = {}; //近七天
var last30th = {}; //近30天
var lastMth = {}; //月
var time = 0; //时间type
var dhzf = 0; //切换type

var myChartC1 = echarts.init(document.getElementById('exchangePay1'));
var myChartC2 = echarts.init(document.getElementById('exchangePay2'));

// // 各平台兑换、支付趋势分析  兑换人数

var optionC = {
    backgroundColor: '#FBFBFB',
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data: ['好品购', '京东', '淘宝', '天猫', '拼多多'],
        align: 'left',
        left: 10,
        icon: "rect", //  字段控制形状  类型包括 circle，rect,line，roundRect，triangle，diamond，pin，arrow，none
        itemWidth: 10, //图例标记的图形宽度
        itemHeight: 10,
        itemGap: 20, // 设置间距
    },
    calculable: true,
    xAxis: [{
        type: 'category',
        boundaryGap: false,
        data: []
    }],
    yAxis: [{
        type: 'value',
    }],
    grid: {
        top: '16%', // 等价于 y: '16%'
        left: '0%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    series: [{
            // name: '好品购',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(0, 208, 208, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            // name: '京东',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(248, 73, 68, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            // name: '淘宝',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(50, 33, 112, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            // name: '天猫',
            type: 'line',
            symbol: 'circle',
            color: ['#66AEDE'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            // name: '拼多多',
            type: 'line',
            symbol: 'circle',
            color: ['#FF9900'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        }
    ]
};


//接口
var platformExchange = function (urls) {
    $.ajax({
        url: serviceUrl1 + urls,
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 各平台兑换、支付趋势分析 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            yesterday = data.data.lastDay;
            last7th = data.data.last7day;
            last30th = data.data.last30day;
            lastMth = data.data.lastMonth;


            jdlastDay = data.data.lastDay.jdRound;
            pddlastDay = data.data.lastDay.pddRound;
            selflastDay = data.data.lastDay.selfRound;
            tblastDay = data.data.lastDay.tbRound;
            tmlastDay = data.data.lastDay.tmRound;

            let jdarr1 = []; //jd数据
            let jdarr2 = []; //时间x轴


            for (var i = 0; i < jdlastDay.length; i++) {
                jdarr1.push(jdlastDay[i].totalCount);
                jdarr2.push(jdlastDay[i].theTime);
            }
            optionC.xAxis[0].data = jdarr2;
            optionC.series[0].data = jdarr1;

            let pddarr1 = []; //pdd数据
            for (var i = 0; i < pddlastDay.length; i++) {
                pddarr1.push(pddlastDay[i].totalCount);
            }
            optionC.series[1].data = pddarr1;

            let selfarr1 = []; //好品购数据
            for (var i = 0; i < selflastDay.length; i++) {
                selfarr1.push(selflastDay[i].totalCount);
            }
            optionC.series[2].data = selfarr1;

            let tbarr1 = []; //tb数据
            for (var i = 0; i < tblastDay.length; i++) {
                tbarr1.push(tblastDay[i].totalCount);
            }
            optionC.series[3].data = tbarr1;

            let tmarr1 = []; //tm数据
            for (var i = 0; i < tmlastDay.length; i++) {
                tmarr1.push(tmlastDay[i].totalCount);
            }
            optionC.series[4].data = tmarr1;
            myChartC1.setOption(optionC);

            let ttm2 = ''
            ttm2 = `
                <div>
                <div><i class="self1"></i>好品购</div>
                    <div>${parseFloat(yesterday.self).toLocaleString()}</div>
                </div>
                <div>
                <div><i class="tm1"></i>天猫</div>
                    <div>${parseFloat(yesterday.tm).toLocaleString()}</div>
                </div>
                <div>
                <div><i class="tb1"></i>淘宝</div>
                    <div>${parseFloat(yesterday.tb).toLocaleString()}</div>
                </div>
                <div>
                <div><i class="jd1"></i>京东</div>
                    <div>${parseFloat(yesterday.jd).toLocaleString()}</div>
                </div>
                <div>
                <div><i class="pdd1"></i>拼多多</div>
                    <div>${parseFloat(yesterday.pdd).toLocaleString()}</div>
                </div>
            `

            // let bightml2 = ttm2;
            document.getElementById('overPeoboxtype').innerHTML = ttm2;
            switch (time) { //时间type
                case 0:
                    lineChartTime(0, '昨日', yesterday);
                    break;
                case 1:
                    lineChartTime(1, '近7日', last7th);
                    break;
                case 2:
                    lineChartTime(2, '近30日', last30th);
                    break;
                case 3:
                    lineChartTime(3, '月', lastMth);
                    break;
                default:
                    console.log('其他')
            }
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
platformExchange();
platformExchange('/coupon-bi/bi/platformExchange')

// 各平台兑换、支付趋势分析tab切换 
$('.tab-box-model2>div').click(function () {
    var index = $(this).index();
    tabType = index;
    var left = index * 56 + (2 * index + 1) * 5;
    $('.tab-box-swiper2>div').css('width', $(this).width());
    $('.tab-box-swiper2>div').css('margin-left', left);
    $(this).addClass('active');
    $(this).siblings().removeClass('active');
    switch (index) {
        case 0:
            platformExchange('/coupon-bi/bi/platformExchange');
            break;
        case 1:
            platformExchange('/coupon-bi/bi/platformPay');
            break;
        default:
            console.log('其他')
    }
})

// 各平台兑换、支付趋势分析时间切换
$('.time-tab-change4>div').click(function () {
    var index = $(this).index();
    activatingType = index;
    switch (index) {
        case 0:
            lineChartTime(0, '昨日', yesterday);
            break;
        case 1:
            lineChartTime(1, '近7日', last7th);
            break;
        case 2:
            lineChartTime(2, '近30日', last30th);
            break;
        case 3:
            lineChartTime(3, '月', lastMth);
            break;
        default:
            console.log('其他')
    }


    $('.time-tab-change4>div').removeClass('activeb');
    $(this).addClass('activeb');
})

var lineChartTime = function (index, test, list) {

    // optionC.legend.data = ['好品购', '京东', '淘宝', '天猫', '拼多多']; //分类
    // optionC.color = ['rgba(0, 208, 208, 1)', 'rgba(248, 73, 68, 1)', 'rgba(50, 33, 112, 1)', '#66AEDE', '#FF9900']; //颜色


    let jdarr1 = []; //jd数据
    let jdarr2 = []; //时间x轴
    console.log(list);

    for (var i = 0; i < list.jdRound.length; i++) {
        jdarr1.push(list.jdRound[i].totalCount);
        jdarr2.push(list.jdRound[i].theTime);
    }
    optionC.xAxis[0].data = jdarr2;
    optionC.series[0].data = jdarr1;

    let pddarr1 = []; //pdd数据
    for (var i = 0; i < list.pddRound.length; i++) {
        pddarr1.push(list.pddRound[i].totalCount);
    }
    optionC.series[1].data = pddarr1;

    let selfarr1 = []; //好品购数据
    for (var i = 0; i < list.selfRound.length; i++) {
        selfarr1.push(list.selfRound[i].totalCount);
    }
    optionC.series[2].data = selfarr1;

    let tbarr1 = []; //tb数据
    for (var i = 0; i < list.tbRound.length; i++) {
        tbarr1.push(list.tbRound[i].totalCount);
    }
    optionC.series[3].data = tbarr1;

    let tmarr1 = []; //tm数据
    for (var i = 0; i < list.tmRound.length; i++) {
        tmarr1.push(list.tmRound[i].totalCount);
    }
    optionC.series[4].data = tmarr1;
    myChartC1.setOption(optionC);

    let ttm2 = ''
    ttm2 = `
    <div>
    <div><i class="self1"></i>好品购</div>
        <div>${parseFloat(list.self).toLocaleString()}</div>
    </div>
    <div>
    <div><i class="tm1"></i>天猫</div>
        <div>${parseFloat(list.tm).toLocaleString()}</div>
    </div>
    <div>
    <div><i class="tb1"></i>淘宝</div>
        <div>${parseFloat(list.tb).toLocaleString()}</div>
    </div>
    <div>
    <div><i class="jd1"></i>京东</div>
        <div>${parseFloat(list.jd).toLocaleString()}</div>
    </div>
    <div>
    <div><i class="pdd1"></i>拼多多</div>
        <div>${parseFloat(list.pdd).toLocaleString()}</div>
    </div>
    `

    // let bightml2 = ttm2;
    document.getElementById('overPeoboxtype').innerHTML = ttm2;
}


// // 各平台兑换、支付趋势分析end



// 兑换、支付频次人数分布start

var myChartDs = echarts.init(document.getElementById('exchangePaypeople'));

var optionD = {
    tooltip: {},
    legend: {
        data: ['兑换', '支付'],
        icon: "rect", //  字段控制形状  类型包括 circle，rect,line，roundRect，triangle，diamond，pin，arrow，none
        itemWidth: 14, //图例标记的图形宽度
        itemHeight: 13,
        itemGap: 20 // 设置间距
    },
    grid: {
        left: '2%',
        right: '2%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        // data: ["0次", "1次", "2次", "3-6次", "7-12次", "13-24次", '25-36次', '37次及以上'],
        type: 'category',
        data: []

    },
    yAxis: {
        type: 'value',
        name: '(单位：人)',
    },
    series: [{
        name: '兑换',
        type: 'bar',
        // data: [420, 420, 300, 200, 100, 70, 30, 30],
        data: [],
        color: ['rgba(0, 208, 208, 1)'],
        barGap: "0%",
        // barWidth:'20'   //设置宽度
    }, {
        name: '支付',
        type: 'bar',
        // data: [150, 150, 280, 150, 80, 110, 70, 30],
        data: [],
        color: ['rgba(255, 153, 0, 1)'],
    }]
};
var frequencyAnalyzeTwo = function () {
    $.ajax({
        url: serviceUrl1 + '/coupon-bi/bi/frequencyAnalyzeTwo',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 兑换、支付频次人数分布 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            var tiemsPeople = [];
            var tiemsPeople2 = [];
            var tiemsArr = [];
            for (var i = 0; i < data.data.exchange.length; i++) {
                tiemsPeople.push(data.data.exchange[i].totalCustomer);
                tiemsArr.push(data.data.exchange[i].deductionCount);
            }
            for (var i = 0; i < data.data.pay.length; i++) {
                tiemsPeople2.push(data.data.pay[i].totalCustomer);
            }
            optionD.xAxis.data = tiemsArr;
            optionD.series[0].data = tiemsPeople;
            optionD.series[1].data = tiemsPeople2;
            myChartDs.setOption(optionD);
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
frequencyAnalyzeTwo();

// 兑换、支付频次人数分布end



//交易
// 兑换、支付预估佣金金额 start
var yugulastday = {}; //昨日
var yugu7th = {}; //近七天
var yugu30th = {}; //近30天
var yuguMth = {}; //月
var timex = 0; //时间type
var yugutype = 0; //切换type

var myChartY = echarts.init(document.getElementById('exchangeYjnum1'));
var myChartF = echarts.init(document.getElementById('exchangeYjnum2'));
var optiony = {
    backgroundColor: '#FBFBFB',
    tooltip: {
        trigger: 'axis',
    },
    legend: {
        data: [],
        align: 'left',
        left: 40,
        icon: "rect", //  字段控制形状  类型包括 circle，rect,line，roundRect，triangle，diamond，pin，arrow，none
        itemWidth: 10, //图例标记的图形宽度
        itemHeight: 10,
        itemGap: 30 // 设置间距
    },
    calculable: true,
    xAxis: [{
        type: 'category',
        boundaryGap: false,
        data: []
    }],
    yAxis: [{
        type: 'value',
    }],
    grid: {
        top: '16%', // 等价于 y: '16%'
        left: '3%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    series: [{
            name: '兑换金额',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(0, 208, 208, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            name: '支付金额',
            type: 'line',
            symbol: 'circle',
            color: ['#FF9946'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }


        },
        {
            name: '预估佣金',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(0, 128, 0, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        }
    ]
};

// 兑换、支付预估佣金金额及支付次数tab切换 
$('.tab-box-model3>div').click(function () {
    var index = $(this).index();
    yugutype = index;
    var left = index * 155;
    $('.tab-box-swiper3>div').css('width', $(this).width());
    $('.tab-box-swiper3>div').css('margin-left', left);
    $(this).addClass('active').siblings().removeClass('active');

    switch (yugutype) {
        case 0:
            exgPayEstAmount(yugutype, '/coupon-bi/bi/exgPayEstAmount');
            break;
        case 1:
            exgPayEstAmount(yugutype, '/coupon-bi/bi/ExgPayTimes');
            break;
        default:
            console.log('其他')
    }
})

//接口
var exgPayEstAmount = function (yugutype, urls) {
    $.ajax({
        url: serviceUrl1 + urls,
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 兑换、支付预估佣金金额及支付次数  ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            yugulastday = data.data.lastDay;
            yugu7th = data.data.last7day;
            yugu30th = data.data.last30day;
            yuguMth = data.data.lastMonth;

            switch (timex) { //时间type
                case 0:
                    lineChartyugu2(0, '昨日', yugulastday, yugutype);
                    break;
                case 1:
                    lineChartyugu2(1, '近7日', yugu7th, yugutype);
                    break;
                case 2:
                    lineChartyugu2(2, '近30日', yugu30th, yugutype);
                    break;
                case 3:
                    lineChartyugu2(3, '月', yuguMth, yugutype);
                    break;
                default:
                    console.log('其他')
            }

        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
exgPayEstAmount();
exgPayEstAmount(0, '/coupon-bi/bi/exgPayEstAmount')


//兑换支付次数
var optionf = {
    backgroundColor: '#FBFBFB',
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data: [],
        align: 'center',
        left: 80,
        icon: "rect", //  字段控制形状  类型包括 circle，rect,line，roundRect，triangle，diamond，pin，arrow，none
        itemWidth: 10, //图例标记的图形宽度
        itemHeight: 10,
        itemGap: 100, // 设置间距
        padding: 50
    },
    calculable: true,
    xAxis: [{
        type: 'category',
        boundaryGap: false,
        data: ['00:00', '06:00', '12:00', '18:00', '23:00']
    }],
    yAxis: [{
        type: 'value'
    }],
    grid: {
        top: '16%', // 等价于 y: '16%'
        left: '3%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    series: [{
            name: '兑换次数',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(0, 208, 208, 1)'],
            // data: [380, 180, 400, 500, 200],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            name: '支付笔数',
            type: 'line',
            symbol: 'circle',
            color: ['#FF9946'],
            // data: [400, 100, 300, 500, 200],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        }
    ]
};

var lineChartyugu2 = function (index, test, list, index2) {
    let estarr1 = []; //预估金额数据
    if (yugutype == 0) {
        var estRound = list.estRound; //预估金额
        optiony.legend.data = ['兑换金额', '支付金额', '预估佣金']; //分类
        optiony.series[0].name = ['兑换金额']
        optiony.series[1].name = ['支付金额']
        optiony.series[2].name = ['预估佣金']
        optiony.color = ['rgba(0, 208, 208, 1)', '#FF9900', 'rgba(0, 128, 0, 1)']; //颜色
        for (var i = 0; i < estRound.length; i++) {
            estarr1.push(estRound[i].totalCount);
        }
    } else if (yugutype == 1) {
        // console.log(11111111);
        optiony.legend.data = ['兑换次数', '支付笔数']; //分类
        optiony.series[0].name = ['兑换次数']
        optiony.series[1].name = ['支付笔数']
        optiony.color = ['rgba(0, 208, 208, 1)', '#FF9900']; //颜色
        console.log(optiony);
    }

    var exchangeRound = list.exchangeRound; //兑换金额
    var payRound = list.payRound; //支付金额

    let exchangearr1 = []; //兑换金额数据
    let exchangearr2 = []; //时间x轴
    for (var i = 0; i < exchangeRound.length; i++) {
        exchangearr1.push(exchangeRound[i].totalCount);
        exchangearr2.push(exchangeRound[i].theTime);
    }
    optiony.xAxis[0].data = exchangearr2;
    optiony.series[0].data = exchangearr1;

    let payarr1 = []; //支付金额数据
    for (var i = 0; i < payRound.length; i++) {
        payarr1.push(payRound[i].totalCount);
    }
    optiony.series[1].data = payarr1;

    optiony.series[2].data = estarr1;

    myChartY.setOption(optiony);
}

var lineChartyugu = function (index, test, list, index2) {


    optionf.legend.data = ['兑换次数', '支付笔数']; //分类
    optionf.color = ['rgba(0, 208, 208, 1)', '#FF9900']; //颜色

    exchangeRound = list.exchangeRound; //兑换金额
    payRound = list.payRound; //支付金额

    let exchangearr11 = []; //兑换次数数据
    let exchangearr22 = []; //时间x轴

    for (var i = 0; i < exchangeRound.length; i++) {
        exchangearr11.push(exchangeRound[i].totalCount);
        exchangearr22.push(exchangeRound[i].theTime);
    }

    optionf.xAxis[0].data = exchangearr22;

    optionf.series[0].data = exchangearr11;
    console.log(optionf.series[0].data);

    let payarr11 = []; //支付笔数数据
    for (var i = 0; i < payRound.length; i++) {
        payarr11.push(payRound[i].totalCount);
    }
    optionf.series[1].data = payarr11;
    $('#exchangeYjnum1').hide();
    $('#exchangeYjnum2').show();
    myChartF.setOption(optionf);


}

// 兑换、支付预估佣金金额及支付次数时间切换
$('.time-tab-change5>div').click(function () {
    var index = $(this).index();
    switch (index) {
        case 0:
            lineChartyugu2(0, '昨日', yugulastday, yugutype);
            break;
        case 1:
            lineChartyugu2(1, '近7日', yugu7th, yugutype);
            break;
        case 2:
            lineChartyugu2(2, '近30日', yugu30th, yugutype);
            break;
        case 3:
            lineChartyugu2(3, '月', yuguMth, yugutype);
            break;
        default:
            console.log('其他')
    }
    $('.time-tab-change5>div').removeClass('active5');
    $(this).addClass('active5');
})

// 兑换、支付预估佣金金额及支付次数end



// 各平台兑换，支付，佣金占比分析start 
var myChartEs = echarts.init(document.getElementById('zhanbiAnalysis1'));

var optionE = {
    tooltip: {},
    legend: {
        data: ['兑换', '支付', '预估佣金', '结算佣金'],
        itemWidth: 14, //图例标记的图形宽度
        itemHeight: 13,
        icon: "rect", //  字段控制形状  类型包括 circle，rect,line，roundRect，triangle，diamond，pin，arrow，none
        top: 10
    },
    grid: {
        top: '16%', // 等价于 y: '16%'
        left: '2%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        data: ["淘宝", "天猫", "好品购", "拼多多", "京东"],
        type: 'category',

    },
    yAxis: {
        type: 'value',
    },
    series: [{
        name: '兑换',
        type: 'bar',
        data: [],
        color: ['rgba(0, 208, 208, 1)'],
        barGap: "0%",
        // barWidth:'20'   //设置宽度
    }, {
        name: '支付',
        type: 'bar',
        data: [],
        color: ['rgba(255, 153, 0, 1)']
    }, {
        name: '预估佣金',
        type: 'bar',
        data: [],
        color: ['rgba(0, 128, 0, 1)']
    }, {
        name: '结算佣金',
        type: 'bar',
        data: [],
        color: ['#55ABEF']
    }]
};


// 各平台兑换，支付，佣金占比分析   数量
var myChartGs = echarts.init(document.getElementById('zhanbiAnalysis2'));
var optionG = {
    tooltip: {},
    legend: {
        data: ['兑换次数', '支付笔数', '已完成订单', '结算佣金订单'],
        top: '5%',
        itemWidth: 13, //图例标记的图形宽度
        itemHeight: 13
    },
    grid: {
        top: '16%', // 等价于 y: '16%'
        left: '2%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        data: ["淘宝", "天猫", "好品购", "拼多多", "京东"],
        type: 'category',
    },
    yAxis: {
        type: 'value',
    },
    series: [{
        name: '兑换次数',
        type: 'bar',
        data: [],
        color: ['rgba(0, 208, 208, 1)'],
        barGap: "0%",
        // barWidth:'20'   //设置宽度
    }, {
        name: '支付笔数',
        type: 'bar',
        data: [],
        color: ['rgba(255, 153, 0, 1)']
    }, {
        name: '已完成订单',
        type: 'bar',
        data: [],
        color: ['rgba(0, 128, 0, 1)']
    }, {
        name: '结算佣金订单',
        type: 'bar',
        data: [],
        color: ['#55ABEF']
    }]
};
//接口
var PlatformExgPayRate = function () {
    $.ajax({
        url: serviceUrl1 + '/coupon-bi/bi/PlatformExgPayRate',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 各平台兑换，支付，佣金占比分析****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            //金额
            var tiemsPeople1 = []; //预估佣金
            var tiemsPeople2 = []; //兑换
            var tiemsPeople3 = []; //支付
            var tiemsPeople4 = []; //结算佣金
            var tiemsArr = [];
            console.log(data.data.amount);
            for (var key in data.data.amount.estAmount) {
                tiemsPeople1.push(data.data.amount.estAmount[key])
            };
            for (var key in data.data.amount.exchange) {
                tiemsPeople2.push(data.data.amount.exchange[key])
            };
            for (var key in data.data.amount.pay) {
                tiemsPeople3.push(data.data.amount.pay[key])
            };
            for (var key in data.data.amount.settleAmount) {
                tiemsPeople4.push(data.data.amount.settleAmount[key])
            }

            optionE.series[0].data = tiemsPeople1;
            //    console.log(optionE.series[0].data);
            optionE.series[1].data = tiemsPeople2;
            // console.log(optionE.series[1].data);
            optionE.series[2].data = tiemsPeople3;
            optionE.series[3].data = tiemsPeople4;
            myChartEs.setOption(optionE);
            // console.log(optionE);

            //数量
            var numsPeople1 = []; //预估佣金
            var numsPeople2 = []; //兑换
            var numsPeople3 = []; //支付
            var numsPeople4 = []; //结算佣金
            var tiemsArr = [];

            for (var key in data.data.num.estAmount) {
                numsPeople1.push(data.data.num.estAmount[key])
            };
            for (var key in data.data.num.exchange) {
                numsPeople2.push(data.data.num.exchange[key])
            };
            for (var key in data.data.num.pay) {
                numsPeople3.push(data.data.num.pay[key])
            };
            for (var key in data.data.num.settleAmount) {
                numsPeople4.push(data.data.num.settleAmount[key])
            }

            optionG.series[0].data = numsPeople1;
            //    console.log(optionE.series[0].data);
            optionG.series[1].data = numsPeople2;
            optionG.series[2].data = numsPeople3;
            optionG.series[3].data = numsPeople4;
            myChartGs.setOption(optionG);
            // console.log(optionG);
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
PlatformExgPayRate();
// 各平台兑换，支付，佣金占比分析 图表切换
$(".rank-tab1").find(".rank-tabx").mouseenter(function () {
    $(this).addClass("active").siblings(".rank-tabx").removeClass("active")
    let $index = $(this).index();

    $(".products4").children(".zhanbiAnalysis").eq($index).addClass("selected").siblings().removeClass("selected")
    if ($index == 0) {
        unit = "（单位：元）"
    } else {
        unit = "（单位：个）"
    }
    document.getElementById('canvas-head-texts').innerHTML = unit;
})

// 各平台兑换，支付，佣金占比分析 end


// 各平台兑换，支付，佣金趋势分析start   
var platformday = {}; //昨日
var platform7th = {}; //近七天
var platform30th = {}; //近30天
var platformMth = {}; //月
var platformtime = 0; //时间type
var platformtype = 0; //切换type
var myChartK = echarts.init(document.getElementById('model3p4'));

var optionk = {
    backgroundColor: '#FBFBFB',
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        // data: ['好品购', '天猫', '淘宝', '京东', '拼多多'],
        align: 'left',
        left: 10,
        icon: "rect", //  字段控制形状  类型包括 circle，rect,line，roundRect，triangle，diamond，pin，arrow，none
        itemWidth: 10, //图例标记的图形宽度
        itemHeight: 10,
        itemGap: 20, // 设置间距
    },
    calculable: true,
    xAxis: [{
        type: 'category',
        boundaryGap: false,
        data: []
    }],
    yAxis: [{
        type: 'value'
    }],
    grid: {
        top: '16%', // 等价于 y: '16%'
        left: '3%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    series: [{
            // name: '京东',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(0, 208, 208, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            // name: '拼多多',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(0, 128, 0, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            // name: '好品购',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(248, 73, 68, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            // name: '淘宝',
            type: 'line',
            symbol: 'circle',
            color: ['#66AEDE'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        },
        {
            // name: '天猫',
            type: 'line',
            symbol: 'circle',
            color: ['rgba(50, 33, 112, 1)'],
            data: [],
            lineStyle: {
                width: 1, // 设置线宽
            }
        }
    ]
};

//接口
var platformTrend = function (urls) {
    $.ajax({
        url: serviceUrl1 + urls,
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 各平台兑换，支付，佣金趋势分析 ****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            platformday = data.data.lastDay;
            platform7th = data.data.last7day;
            platform30th = data.data.last30day;
            platformMth = data.data.lastMonth;

            jdplatformday = data.data.lastDay.jdRound;
            pddplatformday = data.data.lastDay.pddRound;
            selfplatformday = data.data.lastDay.selfRound;
            tbplatformday = data.data.lastDay.tbRound;
            tmplatformday = data.data.lastDay.tmRound;

            let jdlastarr1 = []; //jd数据
            let jdlastarr2 = []; //时间x轴

            for (var i = 0; i < jdplatformday.length; i++) {
                jdlastarr1.push(jdplatformday[i].totalCount);
                jdlastarr2.push(jdplatformday[i].theTime);
            }
            optionk.xAxis[0].data = jdlastarr2;
            optionk.series[0].data = jdlastarr1;

            let pddalstarr1 = []; //pdd数据
            for (var i = 0; i < pddplatformday.length; i++) {
                pddalstarr1.push(pddplatformday[i].totalCount);
            }
            optionk.series[1].data = pddalstarr1;

            let selflastarr1 = []; //好品购数据
            for (var i = 0; i < selfplatformday.length; i++) {
                selflastarr1.push(selfplatformday[i].totalCount);
            }
            optionk.series[2].data = selflastarr1;

            let tblastarr1 = []; //tb数据
            for (var i = 0; i < tbplatformday.length; i++) {
                tblastarr1.push(tbplatformday[i].totalCount);
            }
            optionk.series[3].data = tblastarr1;

            let tmlastarr1 = []; //tm数据
            for (var i = 0; i < tmplatformday.length; i++) {
                tmlastarr1.push(tmplatformday[i].totalCount);
            }
            optionk.series[4].data = tmlastarr1;
            myChartK.setOption(optionk);
            let ttm2 = ''
            ttm2 = `
            <div>
            <div><i class="selfi1"></i>好品购</div>
           <div>${parseFloat(platformday.self).toLocaleString()}</div>
       </div>
       <div>
            <div><i class="tmi1"></i>天猫</div>
           <div>${parseFloat(platformday.tm).toLocaleString()}</div>
       </div>
       <div>
            <div><i class="tbi1"></i>淘宝</div>
           <div>${parseFloat(platformday.tb).toLocaleString()}</div>
       </div>
       <div>
           <div><i class="jdi1"></i>京东</div>
           <div>${parseFloat(platformday.jd).toLocaleString()}</div>
       </div>
       <div>
            <div><i class="pddi1"></i>拼多多</div>
           <div>${parseFloat(platformday.pdd).toLocaleString()}</div>
       </div>
            `
            document.getElementById('overPeoboxtype3').innerHTML = ttm2;
            switch (platformtime) { //时间type
                case 0:
                    lineChartplat(0, '昨日', platformday);
                    break;
                case 1:
                    lineChartplat(1, '近7日', platform7th);
                    break;
                case 2:
                    lineChartplat(2, '近30日', platform30th);
                    break;
                case 3:
                    lineChartplat(3, '月', platformMth);
                    break;
                default:
                    console.log('其他')
            }

        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
platformTrend();
platformTrend('/coupon-bi/bi/platformTrend/exhangeAmount')

// 各平台兑换，支付，佣金趋势分析tab切换 
$('.tab-box-model5>div').click(function () {
    var index = $(this).index();
    tabType = index;
    var left = index * 56 + (2 * index + 1) * 5;
    $('.tab-box-swiper5>div').css('width', $(this).width());
    $('.tab-box-swiper5>div').css('margin-left', left);
    $(this).addClass('active');
    $(this).siblings().removeClass('active');
    switch (index) {
        case 0:
            platformTrend('/coupon-bi/bi/platformTrend/exhangeAmount');
            break;
        case 1:
            platformTrend('/coupon-bi/bi/platformTrend/payAmount');
            break;
        case 2:
            platformTrend('/coupon-bi/bi/platformTrend/estAmount');
            break;
        case 3:
            platformTrend('/coupon-bi/bi/platformTrend/exchangTimes');
            break;
        case 4:
            platformTrend('/coupon-bi/bi/platformTrend/payTimes');
            break;
        default:
            console.log('其他')
    }
})

// 各平台兑换，支付，佣金趋势分析时间切换
$('.time-tab-change6>div').click(function () {
    var index = $(this).index();
    switch (index) {
        case 0:
            lineChartplat(0, '昨日', platformday);
            break;
        case 1:
            lineChartplat(1, '近7日', platform7th);
            break;
        case 2:
            lineChartplat(2, '近30日', platform30th);
            break;
        case 3:
            lineChartplat(3, '月', platformMth);
            break;
        default:
            console.log('其他')
    }
    $('.time-tab-change6>div').removeClass('active6');
    $(this).addClass('active6');
})

var lineChartplat = function (index, test, list) {
    console.log(list)
    // optionk.legend.data = ['好品购', '天猫', '淘宝', '京东', '拼多多']; //分类
    // optionk.color = ['rgba(248, 73, 68, 1)', '#FF9900', 'rgba(0, 128, 0, 1)', 'rgba(50, 33, 112, 1)', 'rgba(0, 208, 208, 1)']; //颜色


    let jdlastarr1 = []; //jd数据
    let jdlastarr2 = []; //时间x轴

    for (var i = 0; i < list.jdRound.length; i++) {
        jdlastarr1.push(list.jdRound[i].totalCount);
        jdlastarr2.push(list.jdRound[i].theTime);
    }
    optionk.xAxis[0].data = jdlastarr2;
    optionk.series[0].data = jdlastarr1;

    let pddalstarr1 = []; //pdd数据
    for (var i = 0; i < list.pddRound.length; i++) {
        pddalstarr1.push(list.pddRound[i].totalCount);
    }
    optionk.series[1].data = pddalstarr1;

    let selflastarr1 = []; //好品购数据
    for (var i = 0; i < list.selfRound.length; i++) {
        selflastarr1.push(list.selfRound[i].totalCount);
    }
    optionk.series[2].data = selflastarr1;

    let tblastarr1 = []; //tb数据
    for (var i = 0; i < list.tbRound.length; i++) {
        tblastarr1.push(list.tbRound[i].totalCount);
    }
    optionk.series[3].data = tblastarr1;

    let tmlastarr1 = []; //tm数据
    for (var i = 0; i < list.tmRound.length; i++) {
        tmlastarr1.push(list.tmRound[i].totalCount);
    }
    optionk.series[4].data = tmlastarr1;
    myChartK.setOption(optionk);

    let ttm2 = ''
    ttm2 = `
        <div>
             <div><i class="selfi1"></i>好品购</div>
            <div>${parseFloat(list.self).toLocaleString()}</div>
        </div>
        <div>
             <div><i class="tmi1"></i>天猫</div>
            <div>${parseFloat(list.tm).toLocaleString()}</div>
        </div>
        <div>
             <div><i class="tbi1"></i>淘宝</div>
            <div>${parseFloat(list.tb).toLocaleString()}</div>
        </div>
        <div>
            <div><i class="jdi1"></i>京东</div>
            <div>${parseFloat(list.jd).toLocaleString()}</div>
        </div>
        <div>
             <div><i class="pddi1"></i>拼多多</div>
            <div>${parseFloat(list.pdd).toLocaleString()}</div>
        </div>
    `
    document.getElementById('overPeoboxtype3').innerHTML = ttm2;
}
// 各平台兑换，支付，佣金趋势分析end

// 商品兑换排行榜start 
// 商品兑换排行榜tab切换 
$('.tab-box-model4>div').click(function () {
    var index = $(this).index();
    tabType = index;
    var left = index * 58 + (2 * index + 1);
    // var left = index*60;
    $('.tab-box-swiper4>div').css('margin-left', left);
    $('.tab-box-model4>div').addClass('active')
    $(this).siblings().removeClass('active')

})

// 商品兑换排行榜
var pintai = {};
var lastDay = {}; //昨日
var last7Day = {}; //近七天
var last30Day = {}; //近30天
var lastMonth = {}; //月
var allArr1 = [];
var gpArr1 = [];
var jdArr1 = [];
var pddArr1 = [];
var tbArr1 = [];
var tmArr1 = [];
var index = 0
var pingtaiIndex = 0;

$('#dhcoupon-tab2>div').click(function () {
    // debugger
    var indexNum = $(this).index();
    index = indexNum
    // var unit="(单位：元)";
    $('#dhcoupon-tab2>div').removeClass('active');
    $(this).addClass('active');
    switch (indexNum) {
        case 0:
            couponRanking('/coupon-bi/bi/skuTop10/amount');
            break;
        case 1:
            couponRanking('/coupon-bi/bi/skuTop10/exchangeNumber');
            break;
        default:
            console.log('其他')
    }
    if (indexNum == 0) {
        unit = "（单位：元）"
    } else {
        unit = "（单位：次）"
    }
    document.getElementById('canvasHeadText1').innerHTML = unit;
    if (indexNum == 0) {
        var RankingHtml = `
                <div>
                    <div>排行</div>
                    <div>商品名称</div>
                    <div class="product-ranking-dz active">兑换金额<i></i></div>
                </div>
            `;
        let ttm = ''
        let ttm2 = ''
        $.each(alllastDay, function (key, value) {


                ttm += `
                        <div>
                                <div>${value.rowNum}</div>
                                <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                                <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                            </div>
                            
                    `

                    ttm2 += `
                    <div>
                            <div>${value.rowNum}</div>
                            <div>${value.commodityName}</div>
                            <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                        </div>
                        
                `
        })

        if (pingtaiIndex == 0) {
            let bightml = RankingHtml + ttm;
            document.getElementById('productRanking1').innerHTML = bightml;
        } else {
            let bightml = RankingHtml + ttm2;
            document.getElementById('productRanking1').innerHTML = bightml;
        }
    } else {
        var RankingHtml = `
                <div>
                    <div>排行</div>
                    <div>商品名称</div>
                    <div class="product-ranking-dz active">兑换次数<i></i></div>
                </div>
            `;
        let ttm = ''
        let ttm2 = ''
        $.each(alllastDay, function (key, value) {
                     ttm += `
                        <div>
                                <div>${value.rowNum}</div>
                                <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                                <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                            </div>
                    
                    `
                    ttm2 += `
                    <div>
                            <div>${value.rowNum}</div>
                            <div>${value.commodityName}</div>
                            <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                        </div>
                        
                `
        })
        if (pingtaiIndex == 0) {
            let bightml = RankingHtml + ttm;
            document.getElementById('productRanking1').innerHTML = bightml;
        } else {
            let bightml = RankingHtml + ttm2;
            document.getElementById('productRanking1').innerHTML = bightml;
        }
    }



})

var couponRanking = function (url) {
    $.ajax({
        url: serviceUrl1 + url,
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 商品兑换排行榜 ****/');
            console.log(data);

            pintai = data.data;

            alllastDay = data.data.all.lastDay;
            allLast7Day = data.data.all.last7day
            allLast30Day = data.data.all.last30day
            allLastMonth = data.data.all.lastMonth

            allArr1 = data.data.all;
            gpArr1 = data.data.gp;
            jdArr1 = data.data.jd;
            pddArr1 = data.data.pdd;
            tbArr1 = data.data.tb;
            tmArr1 = data.data.tm;

            if (index == 0) {
                var RankingHtml = `
                    <div>
                        <div>排行</div>
                        <div>商品名称</div>
                        <div class="product-ranking-dz active">兑换金额<i></i></div>
                    </div>
                `;
                let ttm = ''
                let ttm2=''
                $.each(alllastDay, function (key, value) {
                    ttm += `
                            <div>
                                    <div>${value.rowNum}</div>
                                    <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                                    <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                                </div>
                        
                        `
                        ttm2 += `
                            <div>
                                    <div>${value.rowNum}</div>
                                    <div>${value.commodityName}</div>
                                    <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                                </div>
                        
                        `
                })
                if (pingtaiIndex == 0) {
                    let bightml = RankingHtml + ttm;
                    document.getElementById('productRanking1').innerHTML = bightml;
                } else {
                    let bightml = RankingHtml + ttm2;
                    document.getElementById('productRanking1').innerHTML = bightml;
                }
            } else {
                var RankingHtml = `
                    <div>
                        <div>排行</div>
                        <div>商品名称</div>
                        <div class="product-ranking-dz active">兑换次数<i></i></div>
                    </div>
                `;
                let ttm = ''
                let ttm2=''
                $.each(alllastDay, function (key, value) {

                    ttm += `
                            <div>
                                    <div>${value.rowNum}</div>
                                    <div><text class="pt>${value.deduction}</text>${value.commodityName}</div>
                                    <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                                </div>
                        
                        `
                        ttm2 += `
                        <div>
                                <div>${value.rowNum}</div>
                                <div>${value.commodityName}</div>
                                <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                            </div>
                    
                    `
                })
                if (pingtaiIndex == 0) {
                    let bightml = RankingHtml + ttm;
                    document.getElementById('productRanking1').innerHTML = bightml;
                } else {
                    let bightml = RankingHtml + ttm2;
                    document.getElementById('productRanking1').innerHTML = bightml;
                }
            }

        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }

    })
}
couponRanking();
couponRanking('/coupon-bi/bi/skuTop10/amount'); //默认是金额数据

// let pingtai=

// new
// let pingtaiIndex = 0;
let timeIndex = 0;

//点击平台index
$('#proTimeRanking>div').click(function () {
    pingtaiIndex = $(this).index();
    if (pingtaiIndex == 0) {
        ranking(allArr1);
    } else if (pingtaiIndex == 1) {
        ranking(gpArr1);
    } else if (pingtaiIndex == 2) {
        ranking(jdArr1)
    } else if (pingtaiIndex == 3) {
        ranking(pddArr1)
    } else if (pingtaiIndex == 4) {
        ranking(tbArr1)
    } else if (pingtaiIndex == 5) {
        ranking(tmArr1)
    }
})
//点击时间index
$('#timeChange>div').click(function () {
    timeIndex = $(this).index();
    if (pingtaiIndex == 0) {
        ranking(allArr1);
    } else if (pingtaiIndex == 1) {
        ranking(gpArr1);
    } else if (pingtaiIndex == 2) {
        ranking(jdArr1)
    } else if (pingtaiIndex == 3) {
        ranking(pddArr1)
    } else if (pingtaiIndex == 4) {
        ranking(tbArr1)
    } else if (pingtaiIndex == 5) {
        ranking(tmArr1)
    }
})
let ranking = function (arr) {
    //  console.log(arr)
    document.getElementById('productRanking1').innerHTML = '';
    // let arr=[];
    alllastDay = arr.lastDay;
    allLast7Day = arr.last7day
    allLast30Day = arr.last30day
    allLastMonth = arr.lastMonth

    let eacharr = [];
    if (timeIndex == 0) {
        eacharr = alllastDay;
    } else if (timeIndex == 1) {
        eacharr = allLast7Day;
    } else if (timeIndex == 2) {
        eacharr = allLast30Day;
    } else if (timeIndex == 3) {
        eacharr = allLastMonth;
    }
    if (index == 0) {
        var RankingHtml = `
            <div>
                <div>排行</div>
                <div>商品名称</div>
                <div class="product-ranking-dz active">兑换金额<i></i></div>
            </div>
        `;
        let ttm = ''
        let ttm2=''
        $.each(eacharr, function (key, value) {
            ttm += `
                    <div>
                            <div>${value.rowNum}</div>
                            <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                            <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                        </div>
                
                `
                ttm2 += `
                    <div>
                            <div>${value.rowNum}</div>
                            <div>${value.commodityName}</div>
                            <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                        </div>
                
                `
        })
        if (pingtaiIndex == 0) {
            let bightml = RankingHtml + ttm;
            document.getElementById('productRanking1').innerHTML = bightml;
        } else {
            let bightml = RankingHtml + ttm2;
            document.getElementById('productRanking1').innerHTML = bightml;
        }
    } else {
        var RankingHtml = `
            <div>
                <div>排行</div>
                <div>商品名称</div>
                <div class="product-ranking-dz active">兑换次数<i></i></div>
            </div>
        `;
        let ttm = ''
        let ttm2=''
        $.each(eacharr, function (key, value) {
            ttm += `
                    <div>
                            <div>${value.rowNum}</div>
                            <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                            <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                        </div>
                
                `
                ttm2 += `
                    <div>
                            <div>${value.rowNum}</div>
                            <div>${value.commodityName}</div>
                            <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                        </div>
                
                `
        })
        if (pingtaiIndex == 0) {
            let bightml = RankingHtml + ttm;
            document.getElementById('productRanking1').innerHTML = bightml;
        } else {
            let bightml = RankingHtml + ttm2;
            document.getElementById('productRanking1').innerHTML = bightml;
        }
    }
}

// 商品兑换排行榜end

// 各平台兑换，支付，佣金趋势分析 切换
$('.tab-box-model5>div').click(function () {
    var index = $(this).index();
    tabType = index;
    var left = index * 68;
    $('.tab-box-swiper5>div').css('width', $(this).width());
    $('.tab-box-swiper5>div').css('margin-left', left);
    $(this).addClass('active').siblings().removeClass('active');
})



// 商品支付排行榜start
// 商品支付排行榜tab切换 
$('.tab-box-model6>div').click(function () {
    var index = $(this).index();
    tabType2 = index;
    var left = index * 58 + (2 * index + 1);
    // var left = index*60;
    $('.tab-box-swiper6>div').css('margin-left', left);
    $('.tab-box-model6>div').addClass('active')
    $(this).siblings().removeClass('active')
})

var typePay = {}; //各个平台
var lastDay2 = {}; //昨日
var last7Day2 = {}; //近七天
var last30Day2 = {}; //近30天
var lastMonth2 = {}; //月
var allArr2 = [];
var gpArr2 = [];
var jdArr2 = [];
var pddArr2 = [];
var tbArr2 = [];
var tmArr2 = [];
var index = 0;
var typeIndex = 0; //平台下标

// 点击金额数量切换接口
$('#dhcoupon-tab3>div').click(function () {
    // debugger
    var payindexNum = $(this).index();
    index = payindexNum
    // var unit="(单位：元)";
    $('#dhcoupon-tab3>div').removeClass('active');
    $(this).addClass('active');
    switch (payindexNum) {
        case 0:
            couponRankingpay('/coupon-bi/bi/skuTop10/exchangePayment');
            break;
        case 1:
            couponRankingpay('/coupon-bi/bi/skuTop10/exchangePaymentNumber');
            break;
        default:
            console.log('其他')
    }
    if (index == 0) {
        var RankingHtml = `
        <div>
            <div>排行</div>
            <div>商品名称</div>
            <div class="product-ranking-dz active">支付金额<i></i></div>
        </div>
    `;
        let ttms=''
        let ttm2 = ''
        $.each(alllastDay, function (key, value) {
            ttm2 += `
                <div>
                        <div>${value.rowNum}</div>
                        <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>
            
            `
            ttms += `
                <div>
                        <div>${value.rowNum}</div>
                        <div>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>
            
            `
        })
        if (typeIndex == 0) {
            let bightml2 = RankingHtml + ttm2;
            document.getElementById('productRanking2').innerHTML = bightml2;
        } else {
            let bightml2 = RankingHtml + ttms;
            document.getElementById('productRanking2').innerHTML = bightml2;
        }
    } else {
        var RankingHtml = `
        <div>
            <div>排行</div>
            <div>商品名称</div>
            <div class="product-ranking-dz active">支付次数<i></i></div>
        </div>
    `;
        let ttm2 = ''
        let ttms=''
        $.each(alllastDay, function (key, value) {
            ttm2 += `
                <div>
                        <div>${value.rowNum}</div>
                        <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>
            
            `
            ttms += `
                <div>
                        <div>${value.rowNum}</div>
                        <div>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>
            
            `
        })
        if (typeIndex == 0) {
            let bightml2 = RankingHtml + ttm2;
            document.getElementById('productRanking2').innerHTML = bightml2;
        } else {
            let bightml2 = RankingHtml + ttms;
            document.getElementById('productRanking2').innerHTML = bightml2;
        }
    }
})

var couponRankingpay = function (payurl) {
    $.ajax({
        url: serviceUrl1 + payurl,
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/**** 商品支付排行榜****/');
            console.log(data);
            typePay = data.data;

            alllastDay = data.data.all.lastDay;
            allLast7Day = data.data.all.last7day
            allLast30Day = data.data.all.last30day
            allLastMonth = data.data.all.lastMonth

            allArr2 = data.data.all;
            gpArr2 = data.data.gp;
            jdArr2 = data.data.jd;
            pddArr2 = data.data.pdd;
            tbArr2 = data.data.tb;
            tmArr2 = data.data.tm;

            if (index == 0) {
                var RankingHtml = `
                <div>
                    <div>排行</div>
                    <div>商品名称</div>
                    <div class="product-ranking-dz active">支付金额<i></i></div>
                </div>
            `;
                let ttm2 = ''
                let ttms=''
                $.each(alllastDay, function (key, value) {
                    ttm2 += `
                        <div>
                                <div>${value.rowNum}</div>
                                <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                                <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                            </div>
                    
                    `
                    ttms += `
                        <div>
                                <div>${value.rowNum}</div>
                                <div>${value.commodityName}</div>
                                <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                            </div>
                    
                    `
                })
                if (typeIndex == 0) {
                    let bightml2 = RankingHtml + ttm2;
                    document.getElementById('productRanking2').innerHTML = bightml2;
                } else {
                    let bightml2 = RankingHtml + ttms;
                    document.getElementById('productRanking2').innerHTML = bightml2;
                }
            } else {
                var RankingHtml = `
                <div>
                    <div>排行</div>
                    <div>商品名称</div>
                    <div class="product-ranking-dz active">支付次数<i></i></div>
                </div>
            `;
                let ttm2 = ''
                let ttms=''
                $.each(alllastDay, function (key, value) {
                    ttm2 += `
                        <div>
                                <div>${value.rowNum}</div>
                                <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                                <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                            </div>
                    
                    `
                    ttms += `
                    <div>
                            <div>${value.rowNum}</div>
                            <div>${value.commodityName}</div>
                            <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                        </div>
                
                `
                })
                 if (typeIndex == 0) {
                    let bightml2 = RankingHtml + ttm2;
                document.getElementById('productRanking2').innerHTML = bightml2;
                } else {
                    let bightml2 = RankingHtml + ttms;
                document.getElementById('productRanking2').innerHTML = bightml2;
                }
            }

        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }

    })
}
couponRankingpay();

couponRankingpay('/coupon-bi/bi/skuTop10/exchangePayment'); //默认是金额数据


// let typeIndex = 0; //平台下标
let dataIndex = 0; //时间下标

// //点击平台index
$('#proTimeRanking2>div').click(function () {
    typeIndex = $(this).index();
    if (typeIndex == 0) {
        payranking(allArr2);
    } else if (typeIndex == 1) {
        payranking(gpArr2);
    } else if (typeIndex == 2) {
        payranking(jdArr2)
    } else if (typeIndex == 3) {
        payranking(pddArr2)
    } else if (typeIndex == 4) {
        payranking(tbArr2)
    } else if (typeIndex == 5) {
        payranking(tmArr2)
    }
})
// //点击时间index
$('#timeChange2>div').click(function () {

    dataIndex = $(this).index();
    if (typeIndex == 0) {
        payranking(allArr2);
    } else if (typeIndex == 1) {
        payranking(gpArr2);
    } else if (typeIndex == 2) {
        payranking(jdArr2)
    } else if (typeIndex == 3) {
        payranking(pddArr2)
    } else if (typeIndex == 4) {
        payranking(tbArr2)
    } else if (typeIndex == 5) {
        payranking(tmArr2)
    }
})
let payranking = function (arr) {
    // console.log()'
    document.getElementById('productRanking2').innerHTML = '';
    // let arr=[];
    alllastDay = arr.lastDay;
    allLast7Day = arr.last7day
    allLast30Day = arr.last30day
    allLastMonth = arr.lastMonth

    let eacharr = [];
    if (dataIndex == 0) {
        eacharr = alllastDay;
    } else if (dataIndex == 1) {
        eacharr = allLast7Day;
    } else if (dataIndex == 2) {
        eacharr = allLast30Day;
    } else if (dataIndex == 3) {
        eacharr = allLastMonth;
    }
    if (index == 0) {
        var RankingHtml = `
        <div>
            <div>排行</div>
            <div>商品名称</div>
            <div class="product-ranking-dz active">支付金额<i></i></div>
        </div>
    `;
        let ttm2 = ''
        let ttms=''
        $.each(eacharr, function (key, value) {
            ttm2 += `
                <div>
                        <div>${value.rowNum}</div>
                        <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>
            
            `
            ttms += `
                <div>
                        <div>${value.rowNum}</div>
                        <div>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>
            
            `
        })
        if (typeIndex == 0) {
            let bightml2 = RankingHtml + ttm2;
        document.getElementById('productRanking2').innerHTML = bightml2;
        } else {
            let bightml2 = RankingHtml + ttms;
        document.getElementById('productRanking2').innerHTML = bightml2;
        }
    } else {
        var RankingHtml = `
        <div>
            <div>排行</div>
            <div>商品名称</div>
            <div class="product-ranking-dz active">支付次数<i></i></div>
        </div>
    `;
        let ttm2 = ''
        let ttms=''
        $.each(eacharr, function (key, value) {
            ttm2 += `
                <div>
                        <div>${value.rowNum}</div>
                        <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>
            
            `
            ttms += `
                <div>
                        <div>${value.rowNum}</div>
                        <div>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>
            
            `
        })
        if (typeIndex == 0) {
            let bightml2 = RankingHtml + ttm2;
        document.getElementById('productRanking2').innerHTML = bightml2;
        } else {
            let bightml2 = RankingHtml + ttms;
        document.getElementById('productRanking2').innerHTML = bightml2;
        }
    }
}

// 商品支付排行榜时间切换
$('.time-tab-change2>div').click(function () {
    var index = $(this).index();
    $('.time-tab-change2>div').removeClass('actives');
    $(this).addClass('actives');
})
// 商品支付排行榜end



// 商品结算佣金排行榜start
// 商品结算佣金排行榜 tab切换 
$('.tab-box-model7>div').click(function () {
    var index = $(this).index();
    tabType2 = index;
    var left = index * 58 + (2 * index + 1) + 18;
    // var left = index*60;
    // $('.tab-box-swiper7>div').css('margin-left', left);
    $('.tab-box-model7>div').addClass('active')
    $(this).siblings().removeClass('active')
})

var typeCommission = {}; //各个平台
var allArr3 = [];
var gpArr3 = [];
var jdArr3 = [];
var pddArr3 = [];
var tbArr3 = [];
var tmArr3 = [];
var cardRankingHtml = '';
var indexd = 0;
var typeIndexx = 0; //平台下标
// 点击金额数量切换接口
$('#dhcoupon-tab4>div').click(function () {
    var commissionindex = $(this).index();
    indexd = commissionindex
    $('#dhcoupon-tab4>div').removeClass('active');
    $(this).addClass('active');
    switch (commissionindex) {
        case 0:
            couponRankingCommission('/coupon-bi/bi/skuTop10/SettlementCommission');
            break;
        case 1:
            couponRankingCommission('/coupon-bi/bi/skuTop10/SettlementCommissionNumber');
            break;
        default:
            console.log('其他')
    }
    if (commissionindex == 0) {
        unit = "（单位：元）"
    } else {
        unit = "（单位：个）"
    }
    document.getElementById('canvasHeadText3').innerHTML = unit;

    if (indexd == 0) {
        var RankingHtml = `
        <div>
            <div>排行</div>
            <div>商品名称</div>
            <div class="product-ranking-dz active">结算佣金<i></i></div>
        </div>
    `;
        document.getElementById('productRanking3').innerHTML = RankingHtml;
    } else {
        var RankingHtml = `
        <div>
            <div>排行</div>
            <div>商品名称</div>
            <div class="product-ranking-dz active">结算笔数<i></i></div>
        </div>
    `;
        document.getElementById('productRanking3').innerHTML = RankingHtml;
    }


})

var couponRankingCommission = function (commissionurl) {
    $.ajax({
        url: serviceUrl1 + commissionurl,
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/****商品结算佣金排行榜****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            allArr3 = data.data.all.list;
            jdArr3 = data.data.jd.list;
            pddArr3 = data.data.pdd.list;
            tbArr3 = data.data.tb.list;
            tmArr3 = data.data.tm.list;
            payranking3(allArr3);
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
couponRankingCommission();
couponRankingCommission('/coupon-bi/bi/skuTop10/SettlementCommission'); //默认是金额数据

// let typeIndexx = 0; //平台下标

let payranking3 = function (arr) {
    document.getElementById('productRanking3').innerHTML = '';
    if (indexd == 0) {
        var RankingHtml = `
        <div>
            <div>排行</div>
            <div>商品名称</div>
            <div class="product-ranking-dz active">结算佣金<i></i></div>
        </div>
    `;
        let ttm3 = ''
        let ttmyj=''
        $.each(arr, function (key, value) {
            ttm3 += `
                <div>
                        <div>${value.rowNum}</div>
                        <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>

            `
            ttmyj += `
            <div>
                    <div>${value.rowNum}</div>
                    <div>${value.commodityName}</div>
                    <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                </div>

        `
        })
        
        if (typeIndexx == 0) {
            let bightml3 = RankingHtml + ttm3;
        document.getElementById('productRanking3').innerHTML = bightml3;
        } else {
            let bightml3 = RankingHtml + ttmyj;
        document.getElementById('productRanking3').innerHTML = bightml3;
        }
    } else {
        var RankingHtml = `
        <div>
            <div>排行</div>
            <div>商品名称</div>
            <div class="product-ranking-dz active">结算笔数<i></i></div>
        </div>
    `;
        let ttm3 = ''
        let ttmyj=''
        $.each(arr, function (key, value) {
            ttm3 += `
                <div>
                        <div>${value.rowNum}</div>
                        <div><text class="pt">${value.deduction}</text>${value.commodityName}</div>
                        <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                    </div>

            `
            ttmyj += `
            <div>
                    <div>${value.rowNum}</div>
                    <div>${value.commodityName}</div>
                    <div>${parseFloat(value.exchangeAmout).toLocaleString()}</div>
                </div>

        `
        })
        
        if (typeIndexx == 0) {
            let bightml3 = RankingHtml + ttm3;
        document.getElementById('productRanking3').innerHTML = bightml3;
        } else {
            let bightml3 = RankingHtml + ttmyj;
        document.getElementById('productRanking3').innerHTML = bightml3;
        }
    }
}
// //点击平台index
$('#proTimeRanking3>div').click(function () {
    typeIndexx = $(this).index();
    if (typeIndexx == 0) {
        payranking3(allArr3);
    } else if (typeIndexx == 1) {
        payranking3(jdArr3)
    } else if (typeIndexx == 2) {
        payranking3(pddArr3)
    } else if (typeIndexx == 3) {
        payranking3(tbArr3)
    } else if (typeIndexx == 4) {
        payranking3(tmArr3)
    }
})

// 用户关键流程漏斗分析start

var userKeyFlow = function () {
    $.ajax({
        url: serviceUrl1 + '/coupon-bi/bi/userKeyFlow',
        type: 'get',
        dataType: 'json',
        headers: {
            "Content-Type": "text/plain;charset=UTF-8"
        },
        success: function (data, status) {
            console.log('/****用户关键流程漏斗分析****/');
            console.log(data);
            if (data.code != 0) {
                model(1, 'msg', data.msg);
                return
            }
            var data = data.data;
            var timetabs1 = `<div>(${data.beginDate}至${data.endDate}近30天 单位：个)</div>`;
            document.getElementById('canvas-head-textld').innerHTML = timetabs1;

            var timetabs3 = `<div>${data.totalRate}</div>`;
            document.getElementById('funnel-progress-bar-regUser').innerHTML = timetabs3;

            var timetabs2 = `<div>${parseFloat(data.regUser).toLocaleString()}人</div>`;
            document.getElementById('regUserPeople').innerHTML = timetabs2;

            var timetabs4 = `<div>${parseFloat(data.activeUser).toLocaleString()}人</div>`;
            document.getElementById('activeUser').innerHTML = timetabs4;

            var timetabs5 = `<div>${data.activeRate}</div>`;
            document.getElementById('activeRate').innerHTML = timetabs5;

            var timetabs6 = `<div>${parseFloat(data.exchangeUser).toLocaleString()}人</div>`;
            document.getElementById('exchangeUser').innerHTML = timetabs6;

            var timetabs7 = `<div>${data.exchangeRate}</div>`;
            document.getElementById('exchangeRate').innerHTML = timetabs7;

            var timetabs8 = `<div>${parseFloat(data.paymentUser).toLocaleString()}人</div>`;
            document.getElementById('paymentUser').innerHTML = timetabs8;

            var timetabs9 = `<div>${data.paymentRate}</div>`;
            document.getElementById('paymentRate').innerHTML = timetabs9;

            var color = data.paymentUser / data.exchangeUser * 100 + '%'

            $('.funnel-progress-bar1>div').css('width', data.activeRate);
            $('.funnel-progress-bar2>div').css('width', data.exchangeRate);
            $('.funnel-progress-bar3>div').css('width', data.paymentRate)
            $('.funnel-progress-bar4>div').css('width', color)
        },
        fail: function (err, status) {
            console.log(err);
            model(1, 'msg', err.msg);
        }
    })
}
userKeyFlow();